package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.subsidyapplication.LindiSubsidyApplicationApprovalVO;
import com.minimalist.common.entity.lindi.vo.subsidyapplication.LindiSubsidyApplicationQueryVO;
import com.minimalist.common.entity.lindi.vo.subsidyapplication.LindiSubsidyApplicationVO;
import com.minimalist.common.feign.client.lindi.LindiSubsidyApplicationFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 林地指标交易平台_补贴申请Feign客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author 11987
 */
@Component
public class LindiSubsidyApplicationFeignClientFallbackFactory extends BaseFallbackFactory<LindiSubsidyApplicationFeignClient>{
    private static final Logger log = LoggerFactory.getLogger(LindiSubsidyApplicationFeignClientFallbackFactory.class);


    @Override
    public LindiSubsidyApplicationFeignClient create(Throwable cause){
        return new LindiSubsidyApplicationFeignClient(){

            @Override
            public R<?> addSubsidyApplication(LindiSubsidyApplicationVO subsidyApplicationVO){
                logServiceUnavailable("添加补贴申请", subsidyApplicationVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "添加补贴申请失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteSubsidyApplicationBySubsidyApplicationId(Long subsidyApplicationId){
                logServiceUnavailable("删除补贴申请", subsidyApplicationId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除补贴申请失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updateSubsidyApplicationBySubsidyApplicationId(LindiSubsidyApplicationVO subsidyApplicationVO){
                logServiceUnavailable("修改补贴申请", subsidyApplicationVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "修改补贴申请失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiSubsidyApplicationVO>> getPageSubsidyApplicationList(LindiSubsidyApplicationQueryVO queryVO){
                logServiceUnavailable("分页查询补贴申请列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "分页查询补贴申请列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiSubsidyApplicationVO> getSubsidyApplicationBySubsidyApplicationId(Long subsidyApplicationId){
                logServiceUnavailable("根据补贴申请ID查询补贴申请", subsidyApplicationId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "根据补贴申请ID查询补贴申请失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> approveSubsidyApplication(LindiSubsidyApplicationApprovalVO approvalVO){
                logServiceUnavailable("审批补贴申请", approvalVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "审批补贴申请失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteSubsidyApplicationFileByFileId(Long fileId){
                logServiceUnavailable("删除补贴申请文件", fileId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除补贴申请文件失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}
